﻿using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml.Linq;
using System.Collections.Generic;

namespace DAL
{
    /// <summary>
    /// Summary description for ProductReview
    /// </summary>
    public partial class ProductReview
    {
        public static void DeleteProductReview(int productReviewId)
        {
            using (DAL.EShopDBDataContext db = new EShopDBDataContext())
            {
                db.ProductReview_Delete(productReviewId);
                db.SubmitChanges();
            }
        }

        public static void UpdateProductReview(System.Nullable<int> productReviewId, string body, System.Nullable<int> rating, string subject, System.Nullable<int> productId, string userName, string userEmail)
        {
            using (DAL.EShopDBDataContext db = new EShopDBDataContext())
            {
                db.ProductReview_Update(productReviewId, body, rating, subject, productId, userName, userEmail);
                db.SubmitChanges();
            }
        }

        public static ProductReview[] GetProductReviews(int productId, bool approved)
        {
            using (DAL.EShopDBDataContext db = new EShopDBDataContext())
            {
                return db.GetProductReviews(productId, approved).ToArray<DAL.ProductReview>();
            }
        }

        public static void NewProductReview(string body, string userEmail, string userName, System.Nullable<int> rating,  string subject, System.Nullable<int> productId)
        {
            using (DAL.EShopDBDataContext db = new EShopDBDataContext())
            {
                db.ProductReview_CreateNew(body, userEmail, userName, rating,  subject, productId);
                db.SubmitChanges();
            }
        }
    }
}